package controller

import (
	"api/model"

	"github.com/gin-gonic/gin"
)

const (
	SUCCESS = 10000 + iota
	TOKENTIMEOUTERROR
	ERROR
	UNKOWN
	PARAMTER
	FORBIDDEN
	UNAUTHORIZED
	USERNAMEERROR
	PASSWORDERROR
	TOKENERROR
)

var Msg = map[int]string{
	SUCCESS:           "Success",
	ERROR:             "Error",
	UNKOWN:            "Unkown error",
	PARAMTER:          "Paramter error",
	FORBIDDEN:         "forbidden error",
	UNAUTHORIZED:      "Unauthorized error",
	USERNAMEERROR:     "Username exist or disable",
	PASSWORDERROR:     "Password error",
	TOKENERROR:        "Generate Token error",
	TOKENTIMEOUTERROR: "Token timeout error",
}

func Result(status int, code int, msg string, c *gin.Context) {
	c.JSON(status, model.Response{
		Code: code,
		Msg:  msg,
	})
}

func ResultWithData(status int, code int, msg string, data interface{}, c *gin.Context) {
	c.JSON(status, model.Response{
		Code: code,
		Data: data,
		Msg:  msg,
	})
}

func ResultError(status int, code int, msg string, c *gin.Context) {
	c.JSON(status, model.Response{
		Code: code,
		Msg:  msg,
	})
}

func ResultErrorWithData(status int, code int, data interface{}, msg string, c *gin.Context) {
	c.JSON(status, model.Response{
		Code: code,
		Data: data,
		Msg:  msg,
	})
}
